<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
        }
    </style>
</head>
<body>

 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
     <div class="row demo"  ng-app="MyAPP">
         <h3>Demo1:邮件列表</h3>
         <div ng-view></div>
     </div>
 </div>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular-route.min.js"></script>
<script>
    var messages = [
        {
            "id":"001",
            "sender":"小白一号",
            "subject":"邮件主题，吃饭",
            "date":"20160606",
            "recipients": ["小a","米米","小黑"],
            "content":"今天要吃好喝好!!!"
        },
        {
            "id":"002",
            "sender":"金刚",
            "subject":"邮件主题，散步",
            "date":"May 12, 2014 05:04:00",
            "recipients": ["兔兔","粥粥","小白"],
            "content":"今天锻炼个痛快!!!"
        },
        {
            "id":"003",
            "sender":"carfans",
            "subject":"邮件主题,跳舞",
            "date":"Thu 14, 2014 04:14:00",
            "recipients": ["white_bunny","nb","小米"],
            "content":"今天Happy,Happy!!!"
        }
    ];


    var app=angular.module('MyAPP', ['ngRoute']);
    /**
     * 路由配置
     */
    app.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
        $routeProvider.when('/', {
            controller: 'ListCtrl',
            templateUrl: 'view/list.html'
        }).when('/view/:id', {
            controller: 'DetailCtrl',
            templateUrl: 'view/detail.html'
        }).otherwise({
            redirectTo: '/'
        });
    }]);

    //控制器
    app.controller('ListCtrl',function($scope){
        $scope.messages = messages;
    });
    app.controller('DetailCtrl',function($scope, $routeParams){
        var index = parseInt($routeParams.id)-1;
        $scope.message = messages[index];
    });

</script>
